/**
* DayOfTheWeekQualifier.java 1.0 Jan 15, 2014
*
* Implement a program that prints out the day of the week for a given day 
* (1..31), month (1..12) and year. For example, for a given input "10 October
* 2010" it should print to the screen "Sunday"
*/

import java.util.*;

public class DayOfTheWeekQualifier{
	
	public static void main(String[] args){
		boolean inputRequired = true;
		Scanner in;
		final String[] MONTHS = {"January", "February", "March", "April", "May", "June",
				"July", "August", "September", "October", "November", "December"};
		int day, month, year;
		do {
			System.out.println("Enter the date, i.e. \"10 October 2010\": ");
			in = new Scanner(System.in);
			String input = in.nextLine();
			inputRequired = false;
			
			String[] inputArray = input.split(" ");
			if(inputArray.length != 3){
				System.out.println("Incorrect date format.");
				inputRequired = true;
			}
			
			day = Integer.parseInt(inputArray[0]);
			month = -1;
			for (int i = 0; i < MONTHS.length; i++) 
				//Need to set month to i+1 because January is 1st month not 0
				if (MONTHS[i].equals(inputArray[1])) month = i + 1; 
			if (month == -1) {
				System.out.println("Incorrect month is entered. Try again.");
				inputRequired = true;
			}
			year = Integer.parseInt(inputArray[2]);
		} while (inputRequired);
		
		int a = (14 - month) / 12;
		int y = year - a;
		int m = month + 12 * a - 2;
		
		int result = (7000 + (day + y + y / 4 - y / 100 + y / 400 + (31 * m) / 12)) 
			% 7;
		final String[] DAY_NAMES = {"Sunday", "Monday", "Tuesday", "Wednesday", 
			"Thursday",	"Friday", "Saturday"};
			
		System.out.println("The entered day is " + DAY_NAMES[result]);
		
	}
}